package cn.tedu.truetaste.controller;

import cn.tedu.truetaste.service.IMemberLoginService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 处理openId测试数据相关请求的控制器
 *
 * @author java@tedu.cn
 * @version 0.0.1
 */
@Api(tags = "openId管理模块")
@Slf4j
@RestController
public class MemberLoginController {

    @Autowired
    public IMemberLoginService iMemberLoginService;

    @PostMapping("/user/getOpenId")

    public String getWxOpenId(String code){
        String openId = iMemberLoginService.getUserOpenId(code);
//        String queryToken = iMemberLoginService.getTokenId();
//        System.out.println("3001, "+ queryToken);


        //后续的优化

        //判断数据库有没有这个openid

        //有就返回信息  通过查询的方式

        //没有就存数据库  然后返回信息
        
        return openId;
    }

    @PostMapping("/sendMsg")
    public void sendMsg(){
        //1:获取token（接口调用凭证）
        String token = iMemberLoginService.getTokenId();
        //2:发送订阅消息
        iMemberLoginService.send(token);
    }

}
